From beb8a67ee5f9ecd7f08ecd89c0b7774593eb8342 Mon Sep 17 00:00:00 2001 From: alexmot Date: Tue, 12 Aug 2003 14:57:38 +0000 Subject: [PATCH] Add mapopolis.com mapconverter format as an internally parsed XCSV style. --- gpsbabel/README | 6 +++++ gpsbabel/README.mapconverter | 35 ++++++++++++++++++++++++++ gpsbabel/csv_util.c | 14 +++++++++-- gpsbabel/csv_util.h | 1 + gpsbabel/defs.h | 2 +- gpsbabel/internal_styles.c | 41 +++++++++++++++++++++++++++++-- gpsbabel/style/custom.style | 2 +- gpsbabel/style/mapconverter.style | 35 ++++++++++++++++++++++++++ gpsbabel/util.c | 36 +++++++++++++++++++++++++++ gpsbabel/xcsv.c | 1 + 10 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 gpsbabel/README.mapconverter create mode 100644 gpsbabel/style/mapconverter.style diff --git a/gpsbabel/README b/gpsbabel/README index 2f6cbccc6..87baeab3e 100644 --- a/gpsbabel/README +++ b/gpsbabel/README @@ -385,6 +385,12 @@ THE FORMATS to text so it can be pulled into a spreadsheet or manipulated with text processing tools. + mapconverter + + Mapconverter is a format this is read by Mapopolis.com's mapconverter + application. Full details of it's usage are available in the file + README.mapconverter. + DATA FILTERS GPSBabel supports data filtering. Data filters are invoked from diff --git a/gpsbabel/README.mapconverter b/gpsbabel/README.mapconverter new file mode 100644 index 000000000..2713baf12 --- /dev/null +++ b/gpsbabel/README.mapconverter @@ -0,0 +1,35 @@ +Mapconverter is an application used to create userland maps and map data for +Mapopolis.com's Mapopolis program. The mapconverter format is essentially +waypoint data prepared in a format that the mapconverter application will +accept. + +The steps for using GPSBabel and Mapconverter go something like this: + +Step 1: Create a mapconverter file using gpsbabel. + ./gpsbabel -i geo -f geocaching.loc -o mapconverter -F foo.txt + +Step 2: Launch mapconverter.exe and choose foo.txt as your input file. + Click the begin button to have mapconverter process foo.txt. + +If all goes successfully, you should have a file called "foo.pdb" ready +for syncing with your PDA. Put it wherever Mapopolis thinks it should be +on your PDA. + +NOTES: + +o GPSBabel encodes "foo.txt" to have mapconverter use the output filename + of "foo.pdb". Similarly, if you tell GPSBabel to write output as + "bananagps.txt", mapconverter output will be "bananagps.pdb". + +o The PocketPC version of Mapopolis doesn't notice files with the ".pdb" + extension. To make this work, change the extension to ".mlp" when + copying the mapconverter output to your PocketPC PDA. + +o Mapconverter only works with Mapopolis version 3.x. Mapopolis version + 4 will refuse to load mapconverter maps. There is no known work-around + for this at the time of this writing. + +o Mapconverter is no longer available from the Mapopolis website. If you + need a copy of mapconverter, ask on your local GPS Software discussion + forum and I'm sure someone will have it. As far as I know, It was never + actually acknowledged/supported by Mapopolis to begin with. diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index 77ebc90df..7d9487822 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -819,8 +819,18 @@ xcsv_data_write(void) /* output prologue lines, if any. */ QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) { - ogp = (ogue_t *) elem; - fprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter); + char *ol; + ogp = (ogue_t *) elem; + + ol = strsub(ogp->val, "__FILE__", xcsv_file.fname); + + if (ol) { + fprintf(xcsv_file.xcsvfp, "%s", ol); + free(ol); + } else { + fprintf(xcsv_file.xcsvfp, "%s", ogp->val); + } + fprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter); } switch (global_opts.objective ) { diff --git a/gpsbabel/csv_util.h b/gpsbabel/csv_util.h index 872173d79..7338fa8ba 100644 --- a/gpsbabel/csv_util.h +++ b/gpsbabel/csv_util.h @@ -114,6 +114,7 @@ typedef struct { int ofield_ct; /* actual # of ofields */ FILE * xcsvfp; /* ptr to current *open* data file */ + char * fname; /* ptr to filename of above. */ char * description; /* Description for help text */ char * extension; /* preferred filename extension (for wrappers)*/ diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index cc445c91c..0914ab619 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -342,7 +342,7 @@ void debug_mem_close(); int case_ignore_strcmp(const char *s1, const char *s2); - +char *strsub(char *s, char *search, char *replace); void rtrim(char *s); signed int get_tz_offset(void); const char *get_cache_icon(const waypoint *waypointp); diff --git a/gpsbabel/internal_styles.c b/gpsbabel/internal_styles.c index 1751a6d21..7777360b2 100644 --- a/gpsbabel/internal_styles.c +++ b/gpsbabel/internal_styles.c @@ -69,7 +69,7 @@ static char custom[] = "#\n" "# HEADER STUFF:\n" "#\n" -"PROLOGUE Prologue Line 1\n" +"PROLOGUE Prologue Line 1 __FILE__\n" "PROLOGUE Prologue Line 2\n" "#\n" @@ -243,6 +243,43 @@ static char gpsman[] = "# gpsman.c likes mkshort len = 8, whitespace = 0.\n" ; +static char mapconverter[] = +"# Format: Mapopolis.com Mapconverter\n" +"# Author: Gary Paulson\n" +"# Date: 01/13/2003\n" +"# Requires unsupported mapconverter.exe from mapopolis.com.\n" +"#\n" +"# Modifications by Alex Mottram documented 6/30/2003\n" +"# Change %-40.40s on description output to %-.40s to stop padding.\n" +"# Add QUOTE as badchars, remove COMMA.\n" +"# Removed Mapconverter.exe's README information from style file.\n" +"# Changed OFIELD to IFIELD in case you ever want to read one of these things.\n" +"#\n" +"#\n" +"DESCRIPTION Mapopolis.com Mapconverter CSV\n" +"EXTENSION txt\n" + +"# FILE LAYOUT DEFINITIIONS:\n" + +"FIELD_DELIMITER COMMASPACE\n" +"RECORD_DELIMITER NEWLINE\n" +"BADCHARS \",\n" + +"# Map Info Record (header):\n" +"PROLOGUE M, \"Geocaches\", \"GPSBabel\", Geocaches, __FILE__\n" +"#\n" + +"#\n" +"# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE:\n" +"#\n" +"# L Records:\n" +"IFIELD CONSTANT, \"L\", \"%s\" # [L]ANDMARK\n" +"IFIELD CONSTANT, \"Geocaches\", \"%s\" # Category for Landmark Searches\n" +"IFIELD DESCRIPTION, \"\", \"%-.40s\" # Name\n" +"IFIELD CONSTANT, \"1\", \"%s\" # View at Zoom Level 1 (1-4)\n" +"IFIELD LON_DECIMAL, \"\", \"%08.5f\" # Longitude\n" +"IFIELD LAT_DECIMAL, \"\", \"%08.5f\" # Latitude\n" +; static char mxf[] = "# gpsbabel XCSV style file\n" "#\n" @@ -481,4 +518,4 @@ static char xmapwpt[] = "IFIELD DESCRIPTION, \"\", \"%-.78s\"\n" ; #include "defs.h" -style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "s_and_t", s_and_t } , { "ozi", ozi } , { "nima", nima } , { "mxf", mxf } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } , {0,0}}; +style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "s_and_t", s_and_t } , { "ozi", ozi } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } , {0,0}}; diff --git a/gpsbabel/style/custom.style b/gpsbabel/style/custom.style index 7a158b605..1c871cb06 100644 --- a/gpsbabel/style/custom.style +++ b/gpsbabel/style/custom.style @@ -17,7 +17,7 @@ BADCHARS COMMA # # HEADER STUFF: # -PROLOGUE Prologue Line 1 +PROLOGUE Prologue Line 1 __FILE__ PROLOGUE Prologue Line 2 # diff --git a/gpsbabel/style/mapconverter.style b/gpsbabel/style/mapconverter.style new file mode 100644 index 000000000..cf38b1f15 --- /dev/null +++ b/gpsbabel/style/mapconverter.style @@ -0,0 +1,35 @@ +# Format: Mapopolis.com Mapconverter +# Author: Gary Paulson +# Date: 01/13/2003 +# Requires unsupported mapconverter.exe from mapopolis.com. +# +# Modifications by Alex Mottram documented 6/30/2003 +# Change %-40.40s on description output to %-.40s to stop padding. +# Add QUOTE as badchars, remove COMMA. +# Removed Mapconverter.exe's README information from style file. +# Changed OFIELD to IFIELD in case you ever want to read one of these things. +# +# +DESCRIPTION Mapopolis.com Mapconverter CSV +EXTENSION txt + +# FILE LAYOUT DEFINITIIONS: + +FIELD_DELIMITER COMMASPACE +RECORD_DELIMITER NEWLINE +BADCHARS ", + +# Map Info Record (header): +PROLOGUE M, "Geocaches", "GPSBabel", Geocaches, __FILE__ +# + +# +# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: +# +# L Records: +IFIELD CONSTANT, "L", "%s" # [L]ANDMARK +IFIELD CONSTANT, "Geocaches", "%s" # Category for Landmark Searches +IFIELD DESCRIPTION, "", "%-.40s" # Name +IFIELD CONSTANT, "1", "%s" # View at Zoom Level 1 (1-4) +IFIELD LON_DECIMAL, "", "%08.5f" # Longitude +IFIELD LAT_DECIMAL, "", "%08.5f" # Latitude diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 5f68ec3c1..fb5f624e1 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -305,6 +305,7 @@ fatal(const char *fmt, ...) va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); + va_end(ap); exit(1); } @@ -314,6 +315,7 @@ warning(const char *fmt, ...) va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); + va_end(ap); } /* @@ -535,3 +537,37 @@ double degrees2ddmm(double deg_val) { deg = (signed int) deg_val; return (double) (deg * 100.0) + ((deg_val - deg) * 60.0); } + +/* + * replace a single occurrence of "search" in "s" with "replace". + * Returns an allocated copy if substitution was made, otherwise returns NULL. + * Doesn't try to make an optimally sized dest buffer. + */ +char * +strsub(char *s, char *search, char *replace) +{ + char *p; + int len = strlen(s); + int slen = strlen(search); + int rlen = strlen(replace); + char *d; + + p = strstr(s, search); + if (!slen || !p) { + return NULL; + } + + d = xmalloc(len + rlen); + + /* Copy first part */ + len = p - s; + memcpy(d, s, len); + d[len] = 0; + + /* Copy replacement */ + strcat(d, replace); + + /* Copy last part */ + strcat(d, p + slen); + return d; +} diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index 259992577..b99d5af32 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -493,6 +493,7 @@ xcsv_wr_init(const char *fname, const char *args) } xcsv_file.xcsvfp = fopen(fname, "w"); + xcsv_file.fname = (char *)fname; if (xcsv_file.xcsvfp == NULL) fatal(MYNAME ": Cannot open %s for writing\n", fname); -- 2.30.2